package lumis.portal.webservice.user;

import lumis.portal.user.UserConfig;
import lumis.portal.webservice.WebServiceUtil;

/**
 * Converts {@link User} to/from {@link UserConfig}. 
 *
 * @version $Revision: 5769 $ $Date: 2007-02-01 12:00:07 -0200 (Thu, 01 Feb 2007) $
 * @since 4.0.9
 */
public abstract class UserConverter
{
	public static User convert(UserConfig userConfig)
	{
		User user = new User();
		user.setChannelId(userConfig.getChannelId());
		user.setDisabled(userConfig.isDisabled());
		user.setEmail(userConfig.getEmail());
		user.setFirstName(userConfig.getFirstName());
		user.setId(userConfig.getId());
		user.setLastName(userConfig.getLastName());
		user.setLogin(userConfig.getLogin());
		user.setMiddleName(userConfig.getMiddleName());
		user.setMultiSession(userConfig.isMultiSession());
		user.setType(userConfig.getType());
		user.setOrigin(userConfig.getOrigin());
		return user;
	}
	
	public static UserConfig convert(User user)
	{
		UserConfig userConfig = new UserConfig();
		userConfig.setId(WebServiceUtil.zeroLengthToNull(user.getId()));
		userConfig.setChannelId(WebServiceUtil.zeroLengthToNull(user.getChannelId()));
		userConfig.setDisabled(user.isDisabled());
		userConfig.setEmail(WebServiceUtil.zeroLengthToNull(user.getEmail()));
		userConfig.setFirstName(WebServiceUtil.zeroLengthToNull(user.getFirstName()));
		userConfig.setLastName(WebServiceUtil.zeroLengthToNull(user.getLastName()));
		userConfig.setLogin(WebServiceUtil.zeroLengthToNull(user.getLogin()));
		userConfig.setMiddleName(WebServiceUtil.zeroLengthToNull(user.getMiddleName()));
		userConfig.setMultiSession(user.isMultiSession());
		userConfig.setType(user.getType());
		userConfig.setOrigin(WebServiceUtil.zeroLengthToNull(user.getOrigin()));
		return userConfig;
	}
}